Khai and I iterate on upgrade process, he tweaks track filters, others, I
authorrobertl <robertl>
Fri, 31 Jul 2009 18:32:32 +0000 (18:32 +0000)
committerrobertl <robertl>
Fri, 31 Jul 2009 18:32:32 +0000 (18:32 +0000)
do some general cleanup.

gui/babeldata.h
gui/filterdata.cpp
gui/filterdata.h
gui/filterwidgets.cpp
gui/mainwindow.cpp
gui/mainwindow.h
gui/mainwinui.ui
gui/setup.exe [deleted file]
gui/trackui.ui
gui/upgrade.cpp
gui/upgrade.h

index 8320c39cdce95772020f2461a17d518ab383864a..dae04c2273ecee2bec59744a587e499e1b99001c 100644 (file)
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-// $Id: babeldata.h,v 1.1 2009/07/05 21:14:56 robertl Exp $
+// $Id: babeldata.h,v 1.2 2009/07/31 18:32:32 robertl Exp $
 //------------------------------------------------------------------------
 //
 //  Copyright (C) 2009  S. Khai Mong <khai@mangrai.com>.
@@ -52,7 +52,9 @@ public:
     debugLevel(-1),
     inputBrowse(QString()),
     outputBrowse(QString()),
-    previewGmap(false)
+    previewGmap(false),
+    upgradeCheckMethod(0),
+    upgradeCheckTime(QDateTime(QDate(2001, 1, 1), QTime(0, 0)))
   {
   };
   
@@ -92,6 +94,8 @@ public:
     sg.addVarSetting(new StringSetting("app.outputBrowse", outputBrowse));
 
     sg.addVarSetting(new BoolSetting("app.previewGmap", previewGmap));
+    sg.addVarSetting(new IntSetting("app.upgradeCheckMethod", upgradeCheckMethod));
+    sg.addVarSetting(new DateTimeSetting("app.upgradeCheckTime", upgradeCheckTime));
   }
 
   static const int noType;
@@ -124,6 +128,8 @@ public:
   QString inputBrowse, outputBrowse;
 
   bool  previewGmap;
+  int   upgradeCheckMethod;
+  QDateTime upgradeCheckTime;
 
 };
 
index 9eed46f2bf47e37b3eccb4bde1f13d7fd22579c3..dfae9ab808d6cb86c14b2bc4e37afd3fb41d8ff2 100644 (file)
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-// $Id: filterdata.cpp,v 1.1 2009/07/05 21:14:56 robertl Exp $
+// $Id: filterdata.cpp,v 1.2 2009/07/31 18:32:32 robertl Exp $
 //------------------------------------------------------------------------
 //
 //  Copyright (C) 2009  S. Khai Mong <khai@mangrai.com>.
@@ -88,7 +88,29 @@ QStringList TrackFilterData::makeOptionString()
   if (speed)    s += ",speed";
   if (pack)     s += ",pack";
   if (merge)    s += ",merge";
-  if (split && (pack || merge))    s += ",split";
+  if (split && (pack || merge))  {
+    s += ",split";
+    if (splitTime > 0) 
+      s += QString("=%1%2").arg(splitTime).arg("mhd"[splitTimeUnit]);
+  }
+  if (splitDist > 0) {
+    double d = splitDist;
+    char u = ' ';
+    if (splitDistUnit == 0) { // ft.
+      d /= 5280.0;  u = 'm';
+    }
+    else if (splitDistUnit == 1) { //m
+      d /= 1000.0;  u = 'k';
+    }
+    else if (splitDistUnit == 2) { //km
+      u = 'k';
+    }
+    else if (splitDistUnit == 3) { //m
+      u = 'm';
+    }
+    s += QString(",sdistance=%1%2").arg(d).arg(u);
+  }
+
   if (start)    s += QString(",start=%1").arg(optionDate(startTime, TZ));
   if (stop)     s += QString(",stop=%1").arg(optionDate(stopTime, TZ));
   if (move)     s += QString(",move=%1d%2h%3m%4s").arg(days).arg(hours).arg(mins).arg(secs);
index 38493e2ff8b96f0b5d1c3e9561e57a767525ceba..d6eb852d126ddf6cb18dc055d3b0a2f8cce2811f 100644 (file)
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-// $Id: filterdata.h,v 1.1 2009/07/05 21:14:56 robertl Exp $
+// $Id: filterdata.h,v 1.2 2009/07/31 18:32:32 robertl Exp $
 //------------------------------------------------------------------------
 //
 //  Copyright (C) 2009  S. Khai Mong <khai@mangrai.com>.
@@ -61,7 +61,9 @@ class TrackFilterData: public FilterData  {
                     stop(false),
                     pack(false), merge(false), split(false), 
                     GPSFixes(false), GPSFixesVal(0),
-                    course(false), speed(false)
+                    course(false), speed(false),
+                    splitTime(0), splitTimeUnit(0),
+                    splitDist(0), splitDistUnit(0)
   {
     titleString = "ACTIVE LOG #%Y%m%d";
     stopTime = QDateTime::currentDateTime();
@@ -91,6 +93,10 @@ class TrackFilterData: public FilterData  {
     sg.addVarSetting(new IntSetting("trks.secs", secs));
     sg.addVarSetting(new BoolSetting("trks.title", title));
     sg.addVarSetting(new StringSetting("trks.titleString", titleString));
+    sg.addVarSetting(new IntSetting("trks.splitTime", splitTime));
+    sg.addVarSetting(new IntSetting("trks.splitTimeUnit", splitTimeUnit));
+    sg.addVarSetting(new IntSetting("trks.splitDist", splitDist));
+    sg.addVarSetting(new IntSetting("trks.splitDistUnit", splitDistUnit));
   }
   virtual QStringList makeOptionString();
   
@@ -108,6 +114,8 @@ class TrackFilterData: public FilterData  {
   bool pack, merge, split, GPSFixes;
   int  GPSFixesVal;
   bool course, speed;
+  int  splitTime, splitTimeUnit;
+  int  splitDist, splitDistUnit;
 };
 
 //------------------------------------------------------------------------
index c54a5557a5aea6828a1880d5421308dd2b05ea46..3faf009b61852b5e28c012b7d5469ccf92a86273 100644 (file)
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-// $Id: filterwidgets.cpp,v 1.1 2009/07/05 21:14:56 robertl Exp $
+// $Id: filterwidgets.cpp,v 1.2 2009/07/31 18:32:32 robertl Exp $
 //------------------------------------------------------------------------
 //
 //  Copyright (C) 2009  S. Khai Mong <khai@mangrai.com>.
@@ -41,6 +41,7 @@ TrackWidget::TrackWidget(QWidget *parent, TrackFilterData &tfd): FilterWidget(pa
   addCheckEnabler(ui.GPSFixesCheck, ui.GPSFixesCombo);
   
   connect(ui.mergeCheck, SIGNAL(clicked()) , this, SLOT(mergeCheckX()));
+  connect(ui.splitCheck, SIGNAL(clicked()) , this, SLOT(OtherCheckX()));
   connect(ui.packCheck,  SIGNAL(clicked()),  this, SLOT(packCheckX()));
   connect(ui.startCheck, SIGNAL(clicked()),  this, SLOT(OtherCheckX()));
   connect(ui.stopCheck,   SIGNAL(clicked()), this, SLOT(OtherCheckX()));
@@ -65,12 +66,16 @@ TrackWidget::TrackWidget(QWidget *parent, TrackFilterData &tfd): FilterWidget(pa
   fopts << new IntSpinFilterOption(tfd.hours, ui.hoursSpin);
   fopts << new IntSpinFilterOption(tfd.mins,  ui.minsSpin);
   fopts << new IntSpinFilterOption(tfd.secs,  ui.secsSpin);
+  fopts << new IntSpinFilterOption(tfd.splitTime,  ui.splitTimeSpin, 0, 1000);
+  fopts << new IntSpinFilterOption(tfd.splitDist,  ui.splitDistSpin, 0, 5280);
 
   fopts << new DateTimeFilterOption(tfd.startTime, ui.startEdit);
   fopts << new DateTimeFilterOption(tfd.stopTime,  ui.stopEdit);
 
   fopts << new StringFilterOption(tfd.titleString, ui.titleText);
   fopts << new ComboFilterOption(tfd.GPSFixesVal,  ui.GPSFixesCombo);
+  fopts << new ComboFilterOption(tfd.splitTimeUnit,  ui.splitTimeCombo);
+  fopts << new ComboFilterOption(tfd.splitDistUnit,  ui.splitDistCombo);
   setWidgetValues();
   checkChecks();
 }
@@ -80,7 +85,13 @@ void TrackWidget::OtherCheckX()
 {
   ui.TZCheck->setEnabled(ui.stopCheck->isChecked() || ui.startCheck->isChecked());
   ui.splitCheck->setEnabled(ui.mergeCheck->isChecked() || ui.packCheck->isChecked());
+  bool bb = ui.packCheck->isChecked() &&ui.splitCheck->isChecked();
+  ui.splitTimeSpin->setEnabled(bb);
+  ui.splitTimeCombo->setEnabled(bb);
+  //ui.splitDistSpin->setEnabled(bb); 
+  //ui.splitDistCombo->setEnabled(bb);
 }
+
 //------------------------------------------------------------------------
 void TrackWidget::mergeCheckX()
 {
index beacd8064d61276a7c0017e0ed30b271dd6a7f10..8913080aa5ffe3097a12ea5cba6bf461b2894ddf 100644 (file)
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-// $Id: mainwindow.cpp,v 1.1 2009/07/31 17:59:58 robertl Exp $
+// $Id: mainwindow.cpp,v 1.2 2009/07/31 18:32:32 robertl Exp $
 //------------------------------------------------------------------------
 //
 //  Copyright (C) 2009  S. Khai Mong <khai@mangrai.com>.
@@ -149,7 +149,6 @@ MainWindow::MainWindow(QWidget* parent): QMainWindow(parent)
   connect(ui.actionQuit, SIGNAL(triggered()), this, SLOT(closeActionX()));
   connect(ui.actionHelp, SIGNAL(triggered()), this, SLOT(helpActionX()));
   connect(ui.actionAbout, SIGNAL(triggered()), this, SLOT(aboutActionX()));
-  connect(ui.actionCheckForUpgrade, SIGNAL(triggered()), this, SLOT(checkForUpgradeX()));
 
   connect(ui.inputFormatCombo,  SIGNAL(currentIndexChanged(int)),
          this,                 SLOT(inputFormatChanged(int)));
@@ -188,8 +187,16 @@ MainWindow::MainWindow(QWidget* parent): QMainWindow(parent)
 
   //--- Restore from registry
   restoreSettings();
+  upgrade = new UpgradeCheck();
+  upgrade->checkForUpgrade(babelVersion, bd.upgradeCheckMethod, bd.upgradeCheckTime);
 }
 
+//------------------------------------------------------------------------
+MainWindow::~MainWindow()
+{
+  if (upgrade)
+    delete upgrade;
+}
 //------------------------------------------------------------------------
 void MainWindow::loadDeviceNameCombos()
 {
@@ -758,8 +765,8 @@ void MainWindow::applyActionX()
 
     // Ideally, expost this in the UI.  For now, just split the track
     // if we've no recorded fixes for > 5 mins and we've moved > 300 meters.
-    args << "-x";
-    args << "track,pack,sdistance=0.3k,split=5m";
+    //args << "-x";
+    //args << "track,pack,sdistance=0.3k,split=5m";
 
     args << "-o";
     args << "gpx";
@@ -792,14 +799,19 @@ void MainWindow::applyActionX()
 //------------------------------------------------------------------------
 void MainWindow::closeActionX() 
 {
+  QDateTime wt= upgrade->getUpgradeWarningTime();
+  if (wt.isValid()) {
+    bd.upgradeCheckTime = wt;
+  }
   saveSettings();
+  delete upgrade;
+  upgrade = 0;
   qApp->exit(0);
 }
 
 //------------------------------------------------------------------------
 void MainWindow::closeEvent(QCloseEvent*)  
 {
-  fprintf(stderr, "Close happened\n");
   closeActionX();
 }
 //------------------------------------------------------------------------
@@ -878,12 +890,6 @@ void MainWindow::helpActionX()
 {
   ShowHelp("gpsbabel.html");
 }
-void MainWindow::checkForUpgradeX()
-{
-  Upgrade *foo = new Upgrade(this);
-  foo->show();
-  foo->checkForUpgrade();
-}
 //------------------------------------------------------------------------
 void MainWindow::filtersClicked()
 {
index 31efd665473e450d776e05838e9d033f78e30b4b..be1ff2a49670a5ec54dac0c99a8a105dd102a101 100644 (file)
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-// $Id: mainwindow.h,v 1.1 2009/07/31 17:59:58 robertl Exp $
+// $Id: mainwindow.h,v 1.2 2009/07/31 18:32:32 robertl Exp $
 //------------------------------------------------------------------------
 //
 //  Copyright (C) 2009  S. Khai Mong <khai@mangrai.com>.
@@ -26,6 +26,7 @@
 #include "format.h"
 #include "filterdata.h"
 #include "babeldata.h"
+#include "upgrade.h"
 
 class MainWindow: public QMainWindow {
   Q_OBJECT
@@ -33,14 +34,14 @@ class MainWindow: public QMainWindow {
   
   public:
   MainWindow(QWidget* parent);
-  QString getBabelVersion(void) {return babelVersion;}
+  ~MainWindow();
 
 private:
   Ui_MainWindow     ui;
   QList<Format>  formatList;
+  QString        babelVersion;
   QPixmap        lights[4];
   QStringList    charSets;
-  QString        babelVersion;
   AllFiltersData filterData;
   BabelData      bd;
   bool           fmtChgInterlock;
@@ -74,6 +75,7 @@ private:
   void updateFilterStatus();
   void setWidgetValues();
   void getWidgetValues();
+  UpgradeCheck *upgrade;
 
 protected:
   void closeEvent(QCloseEvent*);
@@ -93,7 +95,6 @@ protected:
   void applyActionX();
   void aboutActionX();
   void helpActionX();
-  void checkForUpgradeX();
   void closeActionX();
   void filtersClicked();
   void resetFormatDefaults();
index 6204585d9df9212858faf950394a6e5d2ad7a25f..aae6063edd84f5088993cb893bdbcbc968ca2189 100644 (file)
      <x>0</x>
      <y>0</y>
      <width>674</width>
-     <height>22</height>
+     <height>26</height>
     </rect>
    </property>
    <widget class="QMenu" name="menuFile">
     <addaction name="actionHelp"/>
     <addaction name="separator"/>
     <addaction name="actionAbout"/>
-    <addaction name="actionCheckForUpgrade"/>
    </widget>
    <addaction name="menuFile"/>
    <addaction name="menuHelp"/>
     <string>Quit</string>
    </property>
   </action>
-  <action name="actionCheckForUpgrade">
-   <property name="text">
-    <string>Check for Upgrade</string>
-   </property>
-  </action>
  </widget>
  <resources>
   <include location="app.qrc"/>
diff --git a/gui/setup.exe b/gui/setup.exe
deleted file mode 100755 (executable)
index 0dbefbf..0000000
Binary files a/gui/setup.exe and /dev/null differ
index d5515ea2503cfafd0bfa46671029a01aaa37f61d..3c4f20e9664289fd1a56b58137f09c53ac34e3a3 100644 (file)
@@ -6,8 +6,8 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>533</width>
-    <height>251</height>
+    <width>558</width>
+    <height>218</height>
    </rect>
   </property>
   <property name="windowTitle">
@@ -19,7 +19,7 @@
   <layout class="QGridLayout" name="gridLayout_2">
    <item row="0" column="0">
     <layout class="QGridLayout" name="gridLayout">
-     <item row="0" column="0" colspan="5">
+     <item row="0" column="0" colspan="2">
       <widget class="QLabel" name="label">
        <property name="font">
         <font>
@@ -51,7 +51,7 @@ If this value contains a percent (%) character, it is treated as a format string
        </property>
       </widget>
      </item>
-     <item row="1" column="1" colspan="4">
+     <item row="1" column="1">
       <widget class="QLineEdit" name="titleText">
        <property name="toolTip">
         <string>the title of the new track is composed of the start time of the track appended to this value. </string>
@@ -72,8 +72,8 @@ This option changes the time of all trackpoints. This might be useful if your tr
        </property>
       </widget>
      </item>
-     <item row="2" column="1" colspan="4">
-      <layout class="QHBoxLayout" name="horizontalLayout">
+     <item row="2" column="1">
+      <layout class="QHBoxLayout" name="horizontalLayout_5">
        <item>
         <widget class="QSpinBox" name="daysSpin"/>
        </item>
@@ -84,6 +84,10 @@ This option changes the time of all trackpoints. This might be useful if your tr
          </property>
         </widget>
        </item>
+      </layout>
+     </item>
+     <item row="2" column="2">
+      <layout class="QHBoxLayout" name="horizontalLayout_4">
        <item>
         <widget class="QSpinBox" name="hoursSpin"/>
        </item>
@@ -94,6 +98,10 @@ This option changes the time of all trackpoints. This might be useful if your tr
          </property>
         </widget>
        </item>
+      </layout>
+     </item>
+     <item row="2" column="3">
+      <layout class="QHBoxLayout" name="horizontalLayout_2">
        <item>
         <widget class="QSpinBox" name="minsSpin"/>
        </item>
@@ -104,6 +112,10 @@ This option changes the time of all trackpoints. This might be useful if your tr
          </property>
         </widget>
        </item>
+      </layout>
+     </item>
+     <item row="2" column="4">
+      <layout class="QHBoxLayout" name="horizontalLayout">
        <item>
         <widget class="QSpinBox" name="secsSpin"/>
        </item>
@@ -235,6 +247,77 @@ If the input has multiple tracks, pack them together before splitting them back
        </property>
       </widget>
      </item>
+     <item row="5" column="3">
+      <layout class="QHBoxLayout" name="horizontalLayout_6">
+       <item>
+        <widget class="QSpinBox" name="splitTimeSpin">
+         <property name="toolTip">
+          <string>If nonzero, the track will be split if the time between two points is greater than this parameter.   If zero, the track will be split by date. </string>
+         </property>
+         <property name="maximum">
+          <number>500</number>
+         </property>
+        </widget>
+       </item>
+       <item>
+        <widget class="QComboBox" name="splitTimeCombo">
+         <item>
+          <property name="text">
+           <string>mins</string>
+          </property>
+         </item>
+         <item>
+          <property name="text">
+           <string>hrs</string>
+          </property>
+         </item>
+         <item>
+          <property name="text">
+           <string>days</string>
+          </property>
+         </item>
+        </widget>
+       </item>
+      </layout>
+     </item>
+     <item row="5" column="4">
+      <layout class="QHBoxLayout" name="horizontalLayout_7">
+       <item>
+        <widget class="QSpinBox" name="splitDistSpin">
+         <property name="toolTip">
+          <string>If nonzero, the input track will be split into several tracks if the distance between successive track points is greater than the distance given as a parameter. </string>
+         </property>
+         <property name="maximum">
+          <number>5280</number>
+         </property>
+        </widget>
+       </item>
+       <item>
+        <widget class="QComboBox" name="splitDistCombo">
+         <item>
+          <property name="text">
+           <string>ft</string>
+          </property>
+         </item>
+         <item>
+          <property name="text">
+           <string>m</string>
+          </property>
+         </item>
+         <item>
+          <property name="text">
+           <string>km</string>
+          </property>
+         </item>
+         <item>
+          <property name="text">
+           <string>mi</string>
+          </property>
+         </item>
+        </widget>
+       </item>
+      </layout>
+     </item>
      <item row="6" column="0" colspan="2">
       <widget class="QWidget" name="widget_5" native="true">
        <property name="toolTip">
@@ -337,7 +420,7 @@ This option computes (or recomputes) a value for the GPS heading at each trackpo
      </property>
      <property name="sizeHint" stdset="0">
       <size>
-       <width>83</width>
+       <width>1</width>
        <height>20</height>
       </size>
      </property>
@@ -350,8 +433,8 @@ This option computes (or recomputes) a value for the GPS heading at each trackpo
      </property>
      <property name="sizeHint" stdset="0">
       <size>
-       <width>20</width>
-       <height>25</height>
+       <width>10</width>
+       <height>2</height>
       </size>
      </property>
     </spacer>
index 4ba06e630d633d69e5f155e8138d2d771eba637c..799cfe03d0510653474b273e5e075f4b94dd897a 100644 (file)
@@ -1,3 +1,5 @@
+// -*- C++ -*-
+// $Id: upgrade.cpp,v 1.2 2009/07/31 18:32:32 robertl Exp $
 /*
     Copyright (C) 2009  Robert Lipe, robertlipe@gpsbabel.org
 
 
 
 #include "upgrade.h"
-#include "mainwindow.h"
-#include "ui_upgrade.h"
 
 #include <QHttp>
-#include <QUrl>
 #include <QMessageBox>
-#include <QFile>
 #include <QDomDocument>
-#include <QDomNode>
-#include <QDomElement>
-#include <QDomNodeList>
 
-Upgrade::Upgrade(QWidget *parent) :
-    QDialog(parent),
-    m_ui(new Ui::Upgrade)
+//static const bool testing = true;
+static const bool testing = false;
+
+static int versionAsNumber(const QString &s) 
 {
-    m_ui->setupUi(this);
+  QStringList list = s.split(".");
+  return (list[0].toInt()<<16 | list[1].toInt() << 8 | list[2].toInt() );
 }
 
-Upgrade::~Upgrade()
+UpgradeCheck::UpgradeCheck(QWidget *parent) :
+  QObject(parent),
+  http(0)
 {
-    delete m_ui;
 }
 
-void Upgrade::changeEvent(QEvent *e)
+UpgradeCheck::~UpgradeCheck()
 {
-    QDialog::changeEvent(e);
-    switch (e->type()) {
-    case QEvent::LanguageChange:
-        m_ui->retranslateUi(this);
-        break;
-    default:
-        break;
-    }
+  if (http) {
+    http->clearPendingRequests();
+    http->abort();
+    delete http;
+    http = 0;
+  }
 }
 
-Upgrade::updateStatus Upgrade::checkForUpgrade()
+void UpgradeCheck::changeEvent(QEvent *)
 {
-  http = new QHttp;
+}
+
+UpgradeCheck::updateStatus UpgradeCheck::checkForUpgrade(const QString &currentVersion,
+                                                        int checkMethod,
+                                                        const QDateTime &lastCheckTime)
+{
+  this->currentVersion = currentVersion;
+  this->upgradeCheckMethod = checkMethod;
 
+  QDateTime soonestCheckTime = lastCheckTime.addDays(1);
+  if (!testing && QDateTime::currentDateTime() < soonestCheckTime) {
+    // Not time to check yet.
+    return UpgradeCheck::updateUnknown;
+  }
+  http = new QHttp;
+  
   connect(http, SIGNAL(requestFinished(int, bool)),
           this, SLOT(httpRequestFinished(int, bool)));
   connect(http, SIGNAL(responseHeaderReceived(const QHttpResponseHeader &)),
           this, SLOT(readResponseHeader(const QHttpResponseHeader &)));
-
+  
   http->setHost("www.gpsbabel.org");
   httpRequestId = http->get("/updates.xml");
-
-  return Upgrade::updateUnknown;
+  
+  return UpgradeCheck::updateUnknown;
 }
 
-void Upgrade::readResponseHeader(const QHttpResponseHeader &responseHeader)
+void UpgradeCheck::readResponseHeader(const QHttpResponseHeader &responseHeader)
 {
   switch (responseHeader.statusCode()) {
   case 200:                   // Ok
@@ -78,57 +88,67 @@ void Upgrade::readResponseHeader(const QHttpResponseHeader &responseHeader)
   case 302:                   // Found
   case 303:                   // See Other
   case 307:                   // Temporary Redirect
-      // these are not error conditions
-      break;
-
+    // these are not error conditions
+    break;
+    
   default:
-      QMessageBox::information(this, tr("HTTP"),
-                               tr("Download failed: %1.")
-                               .arg(responseHeader.reasonPhrase()));
-      httpRequestAborted = true;
-      http->abort();
-    }
+    QMessageBox::information(0, tr("HTTP"),
+                            tr("Download failed: %1.")
+                            .arg(responseHeader.reasonPhrase()));
+    httpRequestAborted = true;
+    http->abort();
+  }
 }
 
-void Upgrade::httpRequestFinished(int requestId, bool error)
+void UpgradeCheck::httpRequestFinished(int requestId, bool error)
 {
-  if(error or requestId != httpRequestId) {
+  if (http == 0 || error)
+    return;
+
+  if (requestId != httpRequestId) 
     return;
-  }
 
   QString oresponse(http->readAll());
+
   QDomDocument document;
-  if (!document.setContent(oresponse)) {
+  if (!document.setContent(oresponse)) 
     return;
-  }
   
-  QString response("snore");
+  QString response;
+  
+  if (testing)
+    currentVersion =  "1.3.1"; // for testing
 
-  QString currentVersion =  "1.3.6"; // FIXME: Work with Khai to pry this out of MainWindow 
   bool allowBeta = false;  // TODO: come from prefs or current version...
 
+  int currentVersionNum = versionAsNumber(currentVersion);
+  
   QDomNodeList upgrades = document.elementsByTagName("update");
-
+  
   for (unsigned int i = 0; i < upgrades.length(); i++) {
     QDomNode upgradeNode = upgrades.item(i);
     QDomElement upgrade = upgradeNode.toElement();
-
+    
     QString updateVersion = upgrade.attribute("version");
     bool updateIsBeta  = upgrade.attribute("type") == "beta";
     bool updateIsMajor = upgrade.attribute("type") == "major";
     bool updateCandidate = updateIsMajor || (updateIsBeta && allowBeta);
+    int updateVersionNum = versionAsNumber(updateVersion);
+    
+    if(updateVersionNum > currentVersionNum && updateCandidate) {
+      response = tr("<center><b>A new version of GPSBabel is available</b><br>"
+                   "Your version is %1 <br>"
+                   "The latest version is %2</center>")
+       .arg(currentVersion)
+       .arg(updateVersion);
 
-    if(updateVersion > currentVersion && updateCandidate) {
-      response = "<b>A new version of GPSBabel is available</b><br/ >";
-      response += "Your version is " + currentVersion + " <br />";;
-      response += "The latest version is " + updateVersion + " <br />";;
       break;  
     }
   }
-
-  // FIXME: this doesn't actually write into the UI's text browser...
-  m_ui->textBrowser->setText(response);
-
-  //QMessageBox::information(this, tr("Finished"), response);
-
+  if (response.length()) {
+    QMessageBox::information(0, tr("Upgrade"), response);
+    upgradeWarningTime = QDateTime(QDateTime::currentDateTime());
+  }
+  delete http;
+  http = 0;
 }
index 7754c7e5489759d10ee5234ceb844751ddbacb1f..6b7681b1e5c3bf2dc4837a8c115548bedaba60d1 100644 (file)
 
 
 #include <QDialog>
-#include "ui_upgrade.h"
+#include <QDateTime>
+#include <QHttp>
 
 class QHttp;
 class QHttpResponseHeader;
 
-namespace Ui {
-    class Upgrade;
-}
-
-class Upgrade : public QDialog {
+class UpgradeCheck : public QObject {
   Q_OBJECT
 public:
-  Upgrade(QWidget *parent = 0);
-  ~Upgrade();
+  UpgradeCheck(QWidget *parent = 0);
+  ~UpgradeCheck();
 
   typedef enum {
     updateUnknown,
@@ -42,21 +39,28 @@ public:
     updateNeeded,
   } updateStatus;
 
-  Upgrade::updateStatus checkForUpgrade(void);
+  UpgradeCheck::updateStatus checkForUpgrade(const QString &babelVersion, 
+                                            int upgradeCheckMethod,
+                                            const QDateTime &lastCheckTime);
+  QDateTime getUpgradeWarningTime() {
+    return upgradeWarningTime;
+  }
 
 protected:
   void changeEvent(QEvent *e);
 
-private:
-//  Ui::Upgrade *m_ui;
-  Ui_Upgrade     *m_ui;
+ private:
+  QString currentVersion;
+  int     upgradeCheckMethod;
   QHttp *http;
   int httpRequestId;
   bool httpRequestAborted;
   QString latestVersion;
+  QDateTime upgradeWarningTime;  // invalid time if this object never issued.
 
 private slots:
   void httpRequestFinished(int requestId, bool error);
+
 //  void httpStateChanged(int state);
   void readResponseHeader(const QHttpResponseHeader &responseHeader);